//package com.zhentao.filter;
//
//
//import com.zhentao.util.AppJwtUtil;
//import io.jsonwebtoken.Claims;
//import org.apache.commons.lang.StringUtils;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
///*
//* App端过滤器
//* */
//@Component
//public class AuthorizeFilter implements Ordered, GlobalFilter {
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        ServerHttpRequest request = exchange.getRequest();
//        ServerHttpResponse response = exchange.getResponse();
//
//        String path = request.getURI().getPath();
////        判断是否包含login登录
//        if(path.contains("login")){
////            放行
//            return chain.filter(exchange);
//        }
////        不包含就获取token
//        String token = request.getHeaders().getFirst("token");
////        判断token是否为空
//        if(StringUtils.isBlank(token)){
//            response.setStatusCode(HttpStatus.UNAUTHORIZED);
//            return response.setComplete();
//        }
////        如果token不为空对token进行校验
//        try{
//            Claims claimsBody = AppJwtUtil.getClaimsBody(token);
//            Object mangerId = claimsBody.get("id");
////            获取用户id
//            ServerHttpRequest serverHttpRequest = request.mutate().headers(httpHeaders -> {
//                httpHeaders.add("mangerId", mangerId + "");
//            }).build();
////            重置head
//            exchange.mutate().request(serverHttpRequest).build();
//
//
//        }catch (Exception e){
////            解密失败
//            response.setStatusCode(HttpStatus.UNAUTHORIZED);
//            return response.setComplete();
//        }
//
//
//
//        return chain.filter(exchange);
//    }
//
//
//    @Override
//    public int getOrder() {
//        return 0;
//    }
//}
